

//
//  EmoticonAttachment.m
//  BiaoQing
//
//  Created by 张帅 on 15/10/13.
//  Copyright © 2015年 ZhangShuai. All rights reserved.
//

#import "EmoticonAttachment.h"

@implementation EmoticonAttachment

+(instancetype)emoticonAttachmentWithEmoctionChs:(NSString *)chs{

    EmoticonAttachment *attament = [[self alloc] init];
    
    attament.chs =chs;
    return attament;

}


+(NSAttributedString *)emoticonAttributeText:(FSEmoticonModel *)emoticon font:(UIFont *)font{

    
    EmoticonAttachment *attachment  =[EmoticonAttachment emoticonAttachmentWithEmoctionChs:emoticon.chs];
    
    attachment.image =[UIImage  imageWithContentsOfFile:emoticon.pngPath];
    
    
    CGFloat height= font.lineHeight;
    
    attachment.bounds = CGRectMake(0, -4, height, height);
    
    // 1) 创建图片属性字符串
    
    NSMutableAttributedString *imageText =[[NSMutableAttributedString alloc] initWithAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
    
            // 2) `添加`字体
    [imageText  addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, 1)];
    
    return imageText;

}
@end
